require "wondercap/lib/deployment/model/area"

extension :revision => :current_local_snapshot do
  task :fill_real_revision do
    area = Wondercap::Deployment::Area.find_by_name("local")
    raise "no current snapshot" unless area && area.current_snapshot
    
    dep = area.current_snapshot.find_deployment_by_name(project_name)
    raise "no deployment for #{project_name} found" unless dep
    
    set :real_revision, dep.revision
  end
end

extension :revision => :current_local_snapshot_with_fallback do
  task :fill_real_revision do
    area = Wondercap::Deployment::Area.find_by_name("local")
    next execute_previous unless area && area.current_snapshot
    
    dep = area.current_snapshot.find_deployment_by_name(project_name)
    next execute_previous unless dep
    
    set :real_revision, dep.revision
  end
end
